# Gettext stuff; based on the contents of the Makefile.in.in file
# distributed with GNU Gettext.
#
# The original copyright notice follows:
#
# Makefile for PO directory in any package using GNU gettext.
# Copyright (C) 1995-1997, 2000-2007 by Ulrich Drepper <drepper@gnu.ai.mit.edu>
#
# This file can be copied and used freely without restrictions.  It can
# be used in projects which are not available under the GNU General Public
# License but which still want to provide support for the GNU gettext
# functionality.
# Please note that the actual code of GNU gettext is covered by the GNU
# General Public License and is *not* in the public domain.
#
# Origin: gettext-0.17

DOMAIN += $(GETTEXT_PACKAGE)

MSGFMT := $(shell which msgfmt)

XGETTEXT := $(shell which xgettext)

MSGMERGE := $(shell which msgmerge)

MSGMERGE_UPDATE := $(MSGMERGE) --update

POFILES += $(shell ls $(srcdir)/Source/WebCore/platform/gtk/po/*.po)

PO_LINGUAS += $(patsubst $(srcdir)/Source/WebCore/platform/gtk/po/%.po,%,$(POFILES))

USER_LINGUAS += $(filter $(LINGUAS),$(PO_LINGUAS))

USE_LINGUAS += $(shell if test -n "$(USER_LINGUAS)" -o -n "$(LINGUAS)"; then LLINGUAS="$(USER_LINGUAS)"; else LLINGUAS="$(PO_LINGUAS)"; fi; for lang in $$LLINGUAS; do printf "$$lang "; done)

MOFILES += $(USE_LINGUAS:%=Source/WebCore/platform/gtk/po/%.mo)

ALL_MOFILES += $(shell echo $(POFILES) | tr ' ' '\n' | sed "s,^$(srcdir)/,,g" | sed 's/\.po/.mo/g')

.po.mo:
	test -d Source/WebCore/platform/gtk/po/ || mkdir -p Source/WebCore/platform/gtk/po/
	@echo "$(MSGFMT) -c -o $@ $<"; \
	$(MSGFMT) -c -o $@ $<

# $(srcdir)/$(DOMAIN).pot is only created when needed. When xgettext finds no
# internationalized messages, no $(srcdir)/$(DOMAIN).pot is created (because
# we don't want to bother translators with empty POT files). We assume that
# LINGUAS is empty in this case, i.e. $(POFILES) and $(MOFILES) are empty.
# In this case, stamp-po is a nop (i.e. a phony target).

# stamp-po is a timestamp denoting the last time at which the CATALOGS have
# been loosely updated. Its purpose is that when a developer or translator
# checks out the package via CVS, and the $(DOMAIN).pot file is not in CVS,
# "make" will update the $(DOMAIN).pot and the $(CATALOGS), but subsequent
# invocations of "make" will do nothing. This timestamp would not be necessary
# if updating the $(CATALOGS) would always touch them; however, the rule for
# $(POFILES) has been designed to not touch files that don't need to be
# changed.
stamp-po: $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot $(MOFILES)
	test ! -d $(top_builddir)/Source/WebCore/platform/gtk/po || \
	 mkdir -p $(top_builddir)/Source/WebCore/platform/gtk/po
	test ! -f $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot || \
	  test -z "$(MOFILES)" || $(MAKE) $(MOFILES)
	@test ! -f $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot || { \
	  echo "touch stamp-po" && \
	  echo timestamp > stamp-poT && \
	  mv stamp-poT stamp-po; \
	}

# This target rebuilds $(DOMAIN).pot; it is an expensive operation.
# Note that $(DOMAIN).pot is not touched if it doesn't need to be changed.
$(DOMAIN).pot-update: $(POTFILES) $(top_builddir)/Source/WebCore/platform/gtk/po/POTFILES
	test -d Source/WebCore/platform/gtk/po/ || mkdir -p Source/WebCore/platform/gtk/po/
	package_gnu=''; \
	if test -n '$(MSGID_BUGS_ADDRESS)' || test '$(PACKAGE_BUGREPORT)' = '@'PACKAGE_BUGREPORT'@'; then \
	  msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \
	else \
	  msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \
	fi; \
	case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
	  '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \
	    $(XGETTEXT) \
	        --default-domain=$(DOMAIN) \
	        --directory=$(srcdir) \
	        --directory=$(srcdir)/Source/WebCore/platform/gtk \
	        --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) \
	        --files-from=$(top_builddir)/Source/WebCore/platform/gtk/po/POTFILES \
	        --copyright-holder='$(COPYRIGHT_HOLDER)' \
	        --msgid-bugs-address="$$msgid_bugs_address" \
	        --keyword=_ \
	        --keyword=N_ \
	        -o $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot \
	    ;; \
	  *) \
	    $(XGETTEXT) \
	        --default-domain=$(DOMAIN) \
	        --directory=$(srcdir) \
	        --directory=$(srcdir)/Source/WebCore/platform/gtk \
	        --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) \
	        --files-from=$(top_builddir)/Source/WebCore/platform/gtk/po/POTFILES \
	        --copyright-holder='$(COPYRIGHT_HOLDER)' \
	        --package-name="$${package_gnu}@PACKAGE@" \
	        --package-version='@VERSION@' \
	        --msgid-bugs-address="$$msgid_bugs_address" \
	        --keyword=_ \
	        --keyword=N_ \
	        -o $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot \
	    ;; \
	esac

# This rule has no dependencies: we don't need to update $(DOMAIN).pot at
# every "make" invocation, only create it when it is missing.
# Only "make $(DOMAIN).pot-update" or "make dist" will force an update.
$(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot:
	$(MAKE) $(DOMAIN).pot-update

# This target rebuilds a PO file if $(DOMAIN).pot has changed.
# Note that a PO file is not touched if it doesn't need to be changed.
update-po-files: $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot
	@for pofile in $(POFILES); do \
	  lang=`echo $$pofile | sed -e 's,.*/,,' -e 's/\.po$$//'`; \
	  if test -f "$(srcdir)/Source/WebCore/platform/gtk/po/$${lang}.po"; then \
	    echo "$${cdcmd}$(MSGMERGE_UPDATE) $(top_srcdir)/Source/WebCore/platform/gtk/po/$${lang}.po $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot"; \
	    $(MSGMERGE_UPDATE) $(top_srcdir)/Source/WebCore/platform/gtk/po/$${lang}.po $(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot; \
	  else \
	    $(MAKE) $${lang}.po-create; \
	  fi; \
	done

update-po: GNUmakefile
	$(MAKE) $(DOMAIN).pot-update
	$(MAKE) update-po-files
	$(MAKE) $(MOFILES)

.nop.po-create:
	@lang=`echo $@ | sed -e 's/\.po-create$$//'`; \
	echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \
	exit 1

# clean rules
CLEANFILES += \
	$(top_builddir)/stamp-po

MAINTAINERCLEANFILES += \
	$(ALL_MOFILES) \
	$(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot

EXTRA_DIST += \
	$(srcdir)/Source/WebCore/platform/gtk/po/ChangeLog \
	$(srcdir)/Source/WebCore/platform/gtk/po/POTFILES.in \
	$(srcdir)/Source/WebCore/platform/gtk/po/README \
	$(wildcard $(srcdir)/Source/WebCore/platform/gtk/po/*.po)

DISTCLEANFILES += \
	$(ALL_MOFILES) \
	$(top_builddir)/Source/WebCore/platform/gtk/po/$(DOMAIN).pot

po-install-data-local: all
	$(MKDIR_P) $(DESTDIR)$(datadir)
	@catalogs='$(MOFILES)'; \
	for cat in $$catalogs; do \
	  cat=`basename $$cat`; \
	  lang=`echo $$cat | sed -e 's/\.mo$$//'`; \
	  dir=$(localedir)/$$lang/LC_MESSAGES; \
	  $(MKDIR_P) $(DESTDIR)$$dir; \
	  if test -r Source/WebCore/platform/gtk/po/$$cat; then realcat=Source/WebCore/platform/gtk/po/$$cat; else realcat=$(srcdir)/$$cat; fi; \
	  $(INSTALL_DATA) $$realcat $(DESTDIR)$$dir/$(DOMAIN).mo; \
	  echo "installing $$realcat as $(DESTDIR)$$dir/$(DOMAIN).mo"; \
	  for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
	    if test -n "$$lc"; then \
	      if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
	        link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \
	        mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
	        mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
	        (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \
	         for file in *; do \
	           if test -f $$file; then \
	             ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \
	           fi; \
	         done); \
	        rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
	      else \
	        if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \
	          :; \
	        else \
	          rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \
	          mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
	        fi; \
	      fi; \
	      rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
	      ln -s ../LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \
	      ln $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \
	      cp -p $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
	      echo "installing $$realcat link as $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo"; \
	    fi; \
	  done; \
	done

po-installdirs-data-local:
	$(MKDIR_P) $(DESTDIR)$(datadir)
	@catalogs='$(MOFILES)'; \
	for cat in $$catalogs; do \
	  cat=`basename $$cat`; \
	  lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
	  dir=$(localedir)/$$lang/LC_MESSAGES; \
	  $(MKDIR_P) $(DESTDIR)$$dir; \
	  for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
	    if test -n "$$lc"; then \
	      if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
	        link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \
	        mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
	        mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
	        (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \
	         for file in *; do \
	           if test -f $$file; then \
	             ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \
	           fi; \
	         done); \
	        rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
	      else \
	        if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \
	          :; \
	        else \
	          rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \
	          mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
	        fi; \
	      fi; \
	    fi; \
	  done; \
	done

po-uninstall-local:
	catalogs='$(MOFILES)'; \
	for cat in $$catalogs; do \
	  cat=`basename $$cat`; \
	  lang=`echo $$cat | sed -e 's/\.mo$$//'`; \
	  for lc in LC_MESSAGES $(EXTRA_LOCALE_CATEGORIES); do \
	    rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
	  done; \
	done

install-data-local: po-install-data-local
installdirs-data-local: po-installdirs-data-local
uninstall-local: po-uninstall-local
